
<%@page language="java" import="java.io.*" %>
<%@page import="java.lang.String"%>

<html>
    <head>
        <title>JSP Page</title>
    </head>
    <body bgcolor="#ffffff" >
        <%
            String langpref = request.getParameter("langpref");

            String osdevpref = request.getParameter("osdevpref");

            String[] osuse = request.getParameterValues("osuse");
            if(osuse == null) osuse = new String[0];

            String[] technologies = request.getParameterValues("technologies");
            if(technologies == null) technologies = new String[0];

            String name = request.getParameter("name");
            String email = request.getParameter("email");

            try{
                PrintWriter fileOut = new PrintWriter(new FileWriter("survey.out",true));

                fileOut.println(langpref);
                fileOut.println(osdevpref);

                for (int i = 0; i <osuse.length; i++)
                {
                    if( i > 0)fileOut.print(",");
                    fileOut.print(osuse[i]);
                }
                fileOut.println();

                for (int i = 0; i <technologies.length; i++)
                {
                     if(i>0)fileOut.print(",");
                     fileOut.println(technologies[i]);
                }
                fileOut.println();
                
                fileOut.println(name);
                fileOut.println(email);
                fileOut.println("-------");
                fileOut.close();
        %>
        
        Thank you for participating in our survey. Your feedback is important!<br>

        <table border="1" width="250px">
            <tr>
                <td>
                    <h3 align="center" valign="middle">Survey Result</h3>
                </td>
            </tr>
            <tr>
                <td>
                    <%out.println("Name : " + name);%>
                </td>
            </tr>
            <tr>
                <td>
                    <%out.println("Email : " +email);%>
                </td>
            </tr>
            <tr>
                <td>
                    <%out.println("Language : " +langpref);%>
                </td>
            </tr>
            <tr>
                <td>
                    <%out.println("Operating : " +osdevpref);%>
                </td>
            </tr>
            <tr>
                <td>
                    <%
                    out.print("OutSource : ");
                        for (int i = 0; i <osuse.length; i++)
                        {
                            if( i > 0)fileOut.print(",");
                            out.println(osuse[i]);
                        }
                    %>
                </td>
            </tr>
            <tr>
                <td>
                    <%
                    out.print("Technology : ");
                        for (int i = 0; i <technologies.length; i++)
                        {
                            if(i>0)fileOut.print(",");
                            fileOut.println(technologies[i]);
                        }
                    %>
                </td>
            </tr>
        </table>

        <%
            }catch(IOException ex){
                application.log("Error savng survey result", ex);
        %>
        <h2>Sorry!</h2>
        Due to a server error, we were unable to save your survey result.
        Please try again later.
        <%
            }
        %>
    </body>
</html>
